package com.xlg.file.center;

import com.xlg.file.center.handler.CsvFileHandler;
import com.xlg.file.center.handler.Handler;
import com.xlg.file.center.utils.Task;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
public class CsvTest {

    public static void main(String[] args) throws Exception {

        List<String> titles = new ArrayList<>();
        titles.add("name");
        titles.add("age");
        titles.add("addr");


        List<User> contents = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            contents.add(User.builder().name("ZhangSan : " + i).age( i  + 1).addr("ChongQing : " + i).build());
        }
        Task<User> task = Task.<User>builder()
                .batchNo(UUID.randomUUID().toString())
                .fileName(UUID.randomUUID().toString())
                .titles(titles)
                .contents(contents)
                .build();

        Handler handler = Handler.builder()
                .filePath("D:\\test\\")
                .msg(new StringBuffer())
                .task(task).build();

        CsvFileHandler csvFileHandler = new CsvFileHandler();
        csvFileHandler.writeTitle(handler);
        csvFileHandler.writeContent(handler);
        log.error("文件追加内容完成.");
    }

}
